package com.cplh.sharding.demo.controller;


import com.cplh.sharding.demo.entry.QzdHjHis;
import com.cplh.sharding.demo.service.QzdHjService;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author: kangzhijin
 * @since: 2022/10/12
 * @version: 1.0
 * @description:
 **/
@Slf4j
@RestController
@RequestMapping("/sharding")
public class ShardingHJTestController {
    @Resource
    private QzdHjService qzdHjService;

    @GetMapping("/test/insertHj/{projectId}")
    public String insertOrder(@PathVariable("projectId") String projectId) {
        QzdHjHis hjHis = new QzdHjHis();
        hjHis.setProjectId(projectId);
        hjHis.setEquipCodeCore(projectId + "-EquipCodeCore");
        hjHis.setWeldCode(projectId + "-WeldCode");
        qzdHjService.save(hjHis);

        return "ok";
    }

    @GetMapping("/test/queryHj/{projectId}")
    public Object queryOrder(@PathVariable("projectId") String projectId) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("projectId", projectId);
        return qzdHjService.queryOrdersMapperNormal(params);
    }

    @GetMapping("/test/queryHj1/{projectId}")
    public Object queryOrder1(@PathVariable("projectId") String projectId) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("projectId", projectId);
        return qzdHjService.queryOrdersMapperNormal1(params);
    }

    @GetMapping("/test/queryHj2/{projectId}")
    public Object queryOrder2(@PathVariable("projectId") String projectId) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("projectId", projectId);
        return qzdHjService.queryOrdersMapperNormal2(params);
    }

    @GetMapping("/test/queryHj3/{projectId}")
    public Object queryOrder3(@PathVariable("projectId") String projectId) {
        QzdHjHis params = new QzdHjHis();
        params.setProjectId(projectId);
        //params.setShardingKey(projectId);
        return qzdHjService.queryOrdersMapperNormal3(params);
    }




}
